﻿using AutoMapper;
using BW.MesProject.Production.Domain.Dto.Output.ProductionReport;
using BW.MesProject.Production.Domain.Model;
using BW.MesProject.Production.Infrastructure;
using BW.MesProject.Public.ErrorCode;
using BW.MesProject.Public.Infrastructure;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BW.MesProject.Production.Application
{
    public class ProductionReportServices : IProductionReportServices
    {
        private readonly IBaseRepository<PRODUCTIONREPORT> _productionReport;
        private readonly IMapper _mapper;
        public ProductionReportServices(IBaseRepository<PRODUCTIONREPORT> productionReport, IMapper mapper)
        {
            _productionReport = productionReport;
            _mapper = mapper;
        }

        public ApiResult<List<ProductionReportOutput>> GetOutPut(string PMId,string WorkOrderCode)
        {
            var productionReports = _productionReport.GetAll().Where(x=>x.WORKORDERCODE==WorkOrderCode && x.PRODUCTIONPROCESSESCODE==PMId).ToList();
            var output = _mapper.Map<List<ProductionReportOutput>>(productionReports);
            if(output==null)
            {
                return new ApiResult<List<ProductionReportOutput>>()
                {
                    Code = ApiEnums.Error,
                    Data = new List<ProductionReportOutput>(),
                    Message = "查询失败"
                };
            }
            return new ApiResult<List<ProductionReportOutput>>
            {
                Code = ApiEnums.Success,
                Data = output,
                Message = "查询成功"
            };
        }
    }
}
